﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Checksums;

namespace ZIP
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //选择解压的zip文件
        private void btnOpenFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Multiselect = true;
            ofd.Title = "请选择zip文件";
            ofd.Filter = "zip文件(*.zip)|*.zip";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                tpGZipPath.Text = ofd.FileName;
            }
        }

        //要压缩的路径
        private void OpenFilePath_Click(object sender, EventArgs e)
        {
            if (OpenFileFolderBrowser.ShowDialog() == DialogResult.OK)
            {
                txtOpenPath.Text = OpenFileFolderBrowser.SelectedPath;
            }
        }

        //解压后存放路径
        private void button2_Click(object sender, EventArgs e)
        {
            if (SaveFileFolderBrowser.ShowDialog() == DialogResult.OK)
            {
                txtSavePath.Text = SaveFileFolderBrowser.SelectedPath;
            }
        }

        //解压
        private void btnGZip_Click(object sender, EventArgs e)
        {
            if (tpGZipPath.Text == "")
            {
                MessageBox.Show("未选择需解压的文件！", "选择文件提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (txtSavePath.Text == "")
            {
                MessageBox.Show("未选择解压后路径！", "选择路径提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            ZipHelpClass zhc = new ZipHelpClass();
            zhc.ZipToFile(tpGZipPath.Text, txtSavePath.Text);
            MessageBox.Show("解压成功");
        }

        //压缩
        private void btnBZip_Click(object sender, EventArgs e)
        {
            if(txtOpenPath.Text=="")
            {
                MessageBox.Show("未选择需压缩的文件夹！", "选择文件夹提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (txtSavePath.Text == "")
            {
                MessageBox.Show("未选择压缩后路径！", "选择路径提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            ZipHelpClass zhc = new ZipHelpClass();
            zhc.DirectoryToZip(txtOpenPath.Text, txtSavePath.Text);
            MessageBox.Show("压缩成功");
        }
    }
}